//
//  WZXButtonViewController.m
//  WWLNetease
//
//  Created by dllo on 15/12/22.
//  Copyright © 2015年 Echo.Jobs. All rights reserved.
//

#import "WZXButtonViewController.h"
#import "WZXFirstTableViewCell.h"
#import "WZXSecondTableViewCell.h"
#import "WZXButtonModel.h"


@interface WZXButtonViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic ,strong)UITableView *myTableView;

@property (nonatomic ,strong)NSMutableArray *AllArray;

@end

@implementation WZXButtonViewController

#pragma mark - 将要出现的时候触发方法
- (void)viewWillAppear:(BOOL)animated {
    
    self.navigationController.navigationBar.hidden = YES;
    
    
}

- (void)loadView
{
    [super loadView];
    self.view.backgroundColor = [UIColor colorWithRed:0.989 green:1.000 blue:0.991 alpha:1.000];
#pragma mark - 自定义buttonNBar界面的navigationBar
    UIImageView *image = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"blueNaBar.jpg"]];
    image.frame = CGRectMake(0, 0, self.view.frame.size.width, 64);
    image.backgroundColor = [UIColor grayColor];
    [self.view addSubview:image];
    
#pragma mark - 自定义buttonNBar上的label
    
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(130 * SIZE, 25 * SIZE, 115 * SIZE, 40 * SIZE)];
    label.text = @"24小时要闻";
    label.textAlignment = NSTextAlignmentCenter;
    label.font = [UIFont systemFontOfSize:20 * SIZE];
    label.textColor = [UIColor whiteColor];
    [self.view addSubview:label];
    
 
#pragma mark - 创建返回button
    [self createLeftButton];
#pragma mark - tableView创建
    [self createTableView];
#pragma mark - 请求数据
    [self getData];
#pragma mark - 注册cell
    [self.myTableView registerClass:[WZXFirstTableViewCell class] forCellReuseIdentifier:@"firstCell"];
    [self.myTableView registerClass:[WZXSecondTableViewCell class] forCellReuseIdentifier:@"secondCell"];

    
}

#pragma mark - tableView创建

- (void)createTableView {
    
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 113) style:UITableViewStylePlain];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    [self.view addSubview:self.myTableView];
    
}

#pragma mark - 上拉刷新
- (void)downTableView {
  
    
}

#pragma mark - 请求数据

- (void)getData {
    
    NSString *urlStr = @"http://c.m.163.com/nc/article/list/T1429173683626/0-20.html";
    [AppTools getDataWithURL:urlStr Block:^(id result) {
      
        self.AllArray = [NSMutableArray array];
        
        NSMutableArray *array = [result objectForKey:@"T1429173683626"];
        
        for (NSMutableDictionary *dic in array) {
            
            WZXButtonModel *model = [[WZXButtonModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [self.AllArray addObject:model];
            
            
        }
        
        [self.myTableView reloadData];
        
    } ErrorBlock:^(NSError *error) {
        
        NSLog(@"请求失败");
    }];
}

#pragma mark - cell的创建
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.row == 0) {

        WZXFirstTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"firstCell" forIndexPath:indexPath];
        WZXButtonModel *model = [self.AllArray objectAtIndex:indexPath.row];
        cell.model = model;
        
        
        return cell;
    }else {
        
        WZXSecondTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"secondCell" forIndexPath:indexPath];
        WZXButtonModel *model = [self.AllArray objectAtIndex:indexPath.row];
        cell.model = model;
        
        if (indexPath.row == 1) {
            
            cell.numImageV.image = [UIImage imageNamed:@"vote_multi_tag@2x.png"];
            cell.numLabel.text = @"2";
            cell.numLabel.textAlignment = NSTextAlignmentCenter;
            cell.numLabel.font = [UIFont systemFontOfSize:13 * SIZE];
            cell.numLabel.textColor = [UIColor whiteColor];
        } else if (indexPath.row == 2) {
            
            cell.numImageV.image = [UIImage imageNamed:@"vote_multi_tag@2x.png"];
            cell.numLabel.text = @"3";
            cell.numLabel.textAlignment = NSTextAlignmentCenter;
            cell.numLabel.font = [UIFont systemFontOfSize:13 * SIZE];
            cell.numLabel.textColor = [UIColor whiteColor];
        } else {
            
            cell.numImageV.image = nil;
            cell.numLabel.text = nil;
        }

        return cell;
    }

    

    
}

#pragma mark - 每个分区有多少个cell
- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//    return self.AllArray.count;
    
    return 100;

}

#pragma mark - 有多少分区
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView {
    
    return 1;
}

#pragma mark - 每个分区cell高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.row == 0) {
        
        return 260 * SIZE;
    }else {
        
        return 90 * SIZE;
    }
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    //取消点击至灰效果
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    NSLog(@"🐶🐶24小时的cell点击方法还没实现哦!!");
    
    
    
}



#pragma mark - 左上角的button
- (void)createLeftButton
{
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    leftButton.frame = CGRectMake(5 * SIZE, 22 * SIZE, 40 * SIZE, 40 * SIZE);
    [leftButton setImage:[UIImage imageNamed:@"iconfont-zuojiantouquan.png"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(leftButtonAction:) forControlEvents:UIControlEventTouchUpInside];
    leftButton.alpha = 0.8;
    [self.view addSubview:leftButton];
    
}

#pragma mark - 左边的返回按钮的点击方法
- (void)leftButtonAction:(UIButton *)btn {
    
    [self.navigationController popToRootViewControllerAnimated:YES];
    
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
